﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class pim_ContactInfo : System.Web.UI.Page
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
        int per_id = 0;
        int emp_id = 0;
        int id = 0;
        if (!Page.IsPostBack) {
            if (Request.QueryString["id"] != null) id = int.Parse(Request.QueryString["id"].ToString());
            if (Request.QueryString["per_id"] != null) per_id = int.Parse(Request.QueryString["per_id"].ToString());
            if (Request.QueryString["emp_id"] != null) emp_id = int.Parse(Request.QueryString["emp_id"].ToString());

            lb_per_id.Text = per_id.ToString();
            lb_emp_id.Text = emp_id.ToString();
            if (id != 0)
            {
                RE_GenericBean contact = DB.getContact(id);
                lb_id.Text=contact.intC1.ToString(); // codigo de persona
                lb_per_id.Text=contact.intC2.ToString(); // codigo de persona
                tb_add1.Text=contact.strC1;
                tb_add2.Text=contact.strC2;
                tb_city.Text=contact.strC3;
                tb_state.Text=contact.strC4;
                tb_zip.Text=contact.strC5;
                tb_country.Text=contact.strC6;
                tb_tel.Text=contact.strC7;
                tb_celular.Text=contact.strC8;
                tb_email.Text=contact.strC11;
                tb_personalemail.Text=contact.strC12;
                if (contact.intC1 != 0) habilitocampos(false);
            }
        }
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        RE_GenericBean contactinf = new RE_GenericBean();
        bool actualiza = false;

        contactinf.intC1 = int.Parse(lb_id.Text);
        contactinf.intC2 = int.Parse(lb_per_id.Text); // codigo de persona
        contactinf.strC1 = tb_add1.Text.Trim();
        contactinf.strC2 = tb_add2.Text.Trim();
        contactinf.strC3 = tb_city.Text.Trim();
        contactinf.strC4 = tb_state.Text.Trim();
        contactinf.strC5 = tb_zip.Text.Trim();
        contactinf.strC6 = tb_country.Text.Trim();
        contactinf.strC7 = tb_tel.Text.Trim();
        contactinf.strC8 = tb_celular.Text.Trim();
        contactinf.strC9 = tb_email.Text.Trim();
        contactinf.strC10 = tb_personalemail.Text.Trim();

        if (contactinf.intC1 != 0) actualiza = true;

        if (DB.InsertaContactInfo(contactinf, actualiza)) {
            Response.Redirect("PersonalInfo.aspx?emp_id=" + lb_emp_id.Text + "&tabindex=1");
        }
    }
  
    protected void Button5_Click(object sender, EventArgs e)
    {
        habilitocampos(true);
    }
    protected void Button6_Click(object sender, EventArgs e)
    {
        int id = 0;
        id = int.Parse(lb_id.Text);
        if (id != 0) {
            int result = DB.DeleteContactInfo(id);
            Response.Redirect("PersonalInfo.aspx?emp_id=" + lb_emp_id.Text + "&tabindex=1");
        }

    }

    private void habilitocampos(bool estado) {
        tb_add1.Enabled = estado;
        tb_add2.Enabled = estado;
        tb_city.Enabled = estado;
        tb_state.Enabled = estado;
        tb_zip.Enabled = estado;
        tb_country.Enabled = estado;
        tb_tel.Enabled = estado;
        tb_celular.Enabled = estado;
        tb_email.Enabled = estado;
        tb_personalemail.Enabled = estado;
    }
}

